package com.ruoyi.project.mydy.dimensionrank.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mydy.dimensionrank.domain.DlDimensionRank;
import com.ruoyi.project.mydy.dimensionrank.service.IDlDimensionRankService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 维度排行Controller
 * 
 * @author mhg
 * @date 2021-10-07
 */
@Controller
@RequestMapping("/mydy/dimensionrank")
public class DlDimensionRankController extends BaseController
{
    private String prefix = "mydy/dimensionrank";

    @Autowired
    private IDlDimensionRankService dlDimensionRankService;

    @RequiresPermissions("mydy:dimensionrank:view")
    @GetMapping()
    public String dimensionrank()
    {
        return prefix + "/dimensionrank";
    }

    /**
     * 查询维度排行列表
     */
    @RequiresPermissions("mydy:dimensionrank:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlDimensionRank dlDimensionRank)
    {
        startPage();
        List<DlDimensionRank> list = dlDimensionRankService.selectDlDimensionRankList(dlDimensionRank);
        return getDataTable(list);
    }

    /**
     * 导出维度排行列表
     */
    @RequiresPermissions("mydy:dimensionrank:export")
    @Log(title = "维度排行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlDimensionRank dlDimensionRank)
    {
        List<DlDimensionRank> list = dlDimensionRankService.selectDlDimensionRankList(dlDimensionRank);
        ExcelUtil<DlDimensionRank> util = new ExcelUtil<DlDimensionRank>(DlDimensionRank.class);
        return util.exportExcel(list, "维度排行数据");
    }

    /**
     * 新增维度排行
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存维度排行
     */
    @RequiresPermissions("mydy:dimensionrank:add")
    @Log(title = "维度排行", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlDimensionRank dlDimensionRank)
    {
        return toAjax(dlDimensionRankService.insertDlDimensionRank(dlDimensionRank));
    }

    /**
     * 修改维度排行
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DlDimensionRank dlDimensionRank = dlDimensionRankService.selectDlDimensionRankById(id);
        mmap.put("dlDimensionRank", dlDimensionRank);
        return prefix + "/edit";
    }

    /**
     * 修改保存维度排行
     */
    @RequiresPermissions("mydy:dimensionrank:edit")
    @Log(title = "维度排行", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlDimensionRank dlDimensionRank)
    {
        return toAjax(dlDimensionRankService.updateDlDimensionRank(dlDimensionRank));
    }

    /**
     * 删除维度排行
     */
    @RequiresPermissions("mydy:dimensionrank:remove")
    @Log(title = "维度排行", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlDimensionRankService.deleteDlDimensionRankByIds(ids));
    }
}
